Groovy Script
In this microlearning, we’ll explore how to leverage Groovy scripts within the eMagiz platform to extend its functionality beyond the standard components available in the flow designer. Groovy scripts offer powerful customization options for situations where the default tools fall short. We’ll discuss where and how to implement Groovy scripts, including their use in filters, transformations, and executors. Key considerations include understanding their complexity, managing dependencies, and ensuring proper documentation. This guide will help you make informed decisions about using Groovy scripts effectively and responsibly.
Should you have any questions, please get in touch with academy@emagiz.com.
1. Prerequisites
- Expert knowledge of the eMagiz platform
2. Key concepts
This microlearning focuses on groovy scripts. A groovy script is a piece of code written in the groovy language that allows you to extend the platform's functionality beyond the mere use of the components supplied via the flow designer.
- Groovy scripts should be viewed as an extension that can be used in fringe cases, not as a standard best practice
- When a groovy script becomes so complex that you are programming, you should consider alternatives to the solution
- Groovy scripts can be used in a filter, transformation, and as part of a standard executor
- Groovy scripts should be well documented as they are though to read for most of our community members
- There is no guarantee from eMagiz that Groovy scripts within models keep working in newer versions of the platform
3. Groovy script
In a low-code platform like eMagiz, you want to prevent using custom scripting as much as possible. However, sometimes in practice, you encounter situations that cannot be realized with the standard toolbox provided within the platform. As a result, we offer the option to use a Groovy script in these situations to achieve the desired solution. In this microlearning, we will look at where you can use a Groovy script and discuss the key considerations when implementing a Groovy script within your model.
3.1 Implementation in Create
To implement a groovy script in Create, you first need to consider what your Groovy script should do. Then, within the flow designer, there are five components available that can handle a Groovy script.
- In case you want the Groovy script to filter out messages, you should implement the Groovy script in a "standard filter" component.
- If you want your Groovy script to always transform your message from a certain format into another format, you should consider using a "standard transformer" component.
- The "standard service activator" is your friend if you need an optional output. So, for example, when you want to do some transformation and check whether a message can continue, you can use the "standard service activator" and have an optional output.
- When you want to split your message based on a Groovy script, you should use the "standard splitter."
- If you want to route messages based on a Groovy script, you should use the "standard router."
Regardless of the component you choose, you always need to select the "Groovy script" option and reference the Groovy resource available on the flow level you want to use within the component.
After you have the component in such a way that the correct Groovy script is called, you are done with the component's configuration and can test the flow using flow testing.
3.2 Key considerations
- To make some groovy scripts work, you need to upload (third-party) Java libraries that are not packaged on default by eMagiz
- To make some groovy scripts work, you need to reference Java libraries via a standard header enricher or as a dummy variable
- The store consists of several groovy scripts that might be of use to you
- Groovy scripts should be viewed as an extension that can be used in fringe cases, not as a standard best practice
- When a groovy script becomes so complex that you are programming, you should consider alternatives to the solution
- Groovy scripts can be used in a filter, transformation, and as part of a standard executor
- Groovy scripts should be well documented as they are though to read for most of our community members
- There is no guarantee from eMagiz that Groovy scripts within models keep working in newer versions of the platform
4. Key takeaways
- To make some groovy scripts work, you need to upload (third-party) Java libraries that are not packaged on default by eMagiz
- To make some groovy scripts work, you need to reference Java libraries via a standard header enricher or as a dummy variable
- The store consists of several groovy scripts that might be of use to you
- Groovy scripts should be viewed as an extension that can be used in fringe cases, not as a standard best practice
- When a groovy script becomes so complex that you are programming, you should consider alternatives to the solution
- Groovy scripts can be used in a filter, transformation, and as part of a standard executor
- Groovy scripts should be well documented as they are though to read for most of our community members
- There is no guarantee from eMagiz that Groovy scripts within models keep working in newer versions of the platform